package org.swfer.UIC 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * 开关按钮
	 * 可选部件 label
	 * 可选状态 selected=frame2
	 * 回调事件 select, unlselect
	 * @author swfer
	 */
	public class ToggleButton extends Component 
	{
		public static const SELECT:String = 'select';
		public static const UNSELECT:String = 'unselect';
		
		protected var _selected:Boolean = false;
		
		public function ToggleButton(view:MovieClip) 
		{
			super(view);
		}
		
		override protected function init():void
		{
			view.mouseChildren = false;
			view.buttonMode = true;
		}
		
		override protected function addEvt():void
		{
			view.addEventListener(MouseEvent.CLICK,onClick);
		}
		
		override protected function removeEvt():void
		{
			view.removeEventListener(MouseEvent.CLICK,onClick);
		}
		
		protected function onClick(e:MouseEvent):void 
		{
			selected = !selected;
			executeCallBack(_selected?SELECT:UNSELECT);
		}
		
		public function get selected():Boolean { return _selected;}
		public function set selected(value:Boolean):void 
		{
			_selected = value;
			view.gotoAndStop(int(value)+1);
		}
		
		public function get label():String { return view['label'].text;}		
		public function set label(value:String):void 
		{
			view['label'].text = value;
		}
	}

}